<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_actions_AjaxNextBlockIdAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$parameters = $this->getRequest()->getParameters();
		
		$documentId = $this->getRequest()->getParameter('pageId');
		$documentLang = $this->getRequest()->getParameter('pageLang');
		
		$tempDocService = m_backoffice_services_TempDocService::getInstance();
		
		if($tempDocService->hasTemporary($documentId, $documentLang))
		{
			$page = $tempDocService->getTemporaryDocument($documentId, $documentLang);
		}
		else
		{
			$page = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Page', $documentId, $documentLang);			
		}		
		
		$blocks = $page->getAllBlocks();

		ksort($blocks);

		if(!is_array($blocks) || count($blocks) == 0)
		{
			echo "1";
		}
		else
		{
			$block = end($blocks);
			echo $block['blockId']+1;
		}
	}
    
	public function errorHandler()
	{
		return null;
	}
}